<template>
	<a-popconfirm :title="props.title" @confirm="dataExport">
		<a-button :loading="loading">
			<template #icon><upload-outlined /></template>
			{{ props.buttonName }}
		</a-button>
	</a-popconfirm>
</template>
<script setup name="DataExport">
	import { notification } from 'ant-design-vue'
	import file from '@/utils/file'
	const loading = ref(false)
	const emit = defineEmits({ dataExport: null })
	const props = defineProps({
		title: {
			type: String,
			default: () => '确定要导出当前数据吗？'
		},
		buttonName: {
			type: String,
			default: () => '导出'
		}
	})
	// 批量删除
	const dataExport = () => {
		loading.value = true
		// // 发起方法调用，谁的谁来实现
		emit('dataExport', (data) => {
			loading.value = false
			if (data) {
				notification['success']({
					message: '导出成功',
					description: '文件导出成功,正在下载到本地!'
				})
				file.downLoadFile(data)
			} else {
				notification['error']({
					message: '导出失败',
					description: '文件导出失败!'
				})
			}
		})
	}
</script>

<style lang="scss" scoped></style>
